/*!
 * \file Debug.cpp
 * \brief Debugging module.
 * \author Nus
 * \date 2008/02/16, 05:22
 */

#include "Debug.h"

#ifndef D_BUFF_LEN
#define D_BUFF_LEN 512
#endif

// Log to console.
void LogStr(const s8* format, ...)
{
  s8 buffer[D_BUFF_LEN];
  va_list args;
  va_start(args, format);

  vsnprintf(buffer, sizeof(buffer), format, args);
  buffer[D_BUFF_LEN - 1] = '\0';
  printf(buffer);

  va_end(args);
}

// Log to console.
void AssertEx(s32 cond, const s8* file, u32 line, const s8* format, ...)
{
  if(!cond) {
    printf("!!! Assertion failed... !!!\n");

    s8 buffer[D_BUFF_LEN];
    va_list args;
    va_start(args, format);
  
    vsnprintf(buffer, sizeof(buffer), format, args);
    buffer[D_BUFF_LEN - 1] = '\0';
    printf(buffer);
  
    va_end(args);
  
    printf("File: %s, line %d.\n", file, line);
    assert(0);
  }
}

// Verify.
void Verify(s32 cond, const s8* format, ...)
{
  if(!cond) {
    s8 buffer[D_BUFF_LEN];
    va_list args;
    va_start(args, format);
  
    vsnprintf(buffer, sizeof(buffer), format, args);
    buffer[D_BUFF_LEN - 1] = '\0';
    printf(buffer);
  
    va_end(args);
  }
}
